# 判断是否安装squid
echo '第一步: 安装 squid';
if ! type squid >/dev/null 2>&1; then
    echo 'squid 未安装,  开始安装';
    yum -y install squid;
    echo 'squid 安装成功';
else
    echo 'squid 已安装';
fi
# 判断是否安装httpd
echo '第二步: 安装 httpd';
if ! type httpd >/dev/null 2>&1; then
    echo 'httpd 未安装,  开始安装';
    systemver=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
    if [[ $systemver = "8" ]];then
    yum install httpd -y
    else 
    yum -y install httpd htpasswd;
    fi
    echo 'httpd 安装成功';
else
    echo 'httpd 已安装';
fi
# 第三步: 配置代理服务器
echo '第三步: 配置代理服务器';
#read -p $'Set Squid proxy server account:\x0a' username;
#read -p $'Set Squid proxy server password:\x0a' password;
#echo $username;
#echo $password;
username=`</dev/urandom tr -dc 0-9a-z|head -c ${1:-8}`
password=`</dev/urandom tr -dc 0-9a-z|head -c ${1:-8}`
htpasswd -bc /etc/squid/passwd $username $password;
# 覆盖squid代理服务器配置
yes | cp squid.conf /etc/squid/squid.conf;

# iptables -I INPUT -p tcp --dport 3218 -j ACCEPT

# 启动
service squid start
#设置开机自启
chkconfig squid on

# 将账号密码填到代理配置中
echo '已完成代理服务器，请将下面账号密码配置进代理配置项中';
echo "代理账号:${username}";
echo "代理密码:${password}";